gtkmenu: displace popups by their css margin
authorLars Uebernickel <lars.uebernickel@canonical.com>
Wed, 5 Mar 2014 11:59:24 +0000 (12:59 +0100)
committerLars Uebernickel <lars.uebernickel@canonical.com>
Thu, 6 Mar 2014 09:44:28 +0000 (10:44 +0100)
Without a margin, the pointer is above the first (or last) menu item,
making it easy to accidentally activate that item.

https://bugzilla.gnome.org/show_bug.cgi?id=591258

gtk/gtkmenu.c

index a31ec09004ab4a6d23387c01f983e6b359704ad9..acebe7626caff30b8069f1284501ea88bbce33de 100644 (file)
@@ -2525,6 +2525,19 @@ get_menu_padding (GtkWidget *widget,
   gtk_style_context_get_padding (context, state, padding);
 }
 
+static void
+get_menu_margin (GtkWidget *widget,
+                 GtkBorder *margin)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+
+  gtk_style_context_get_margin (context, state, margin);
+}
+
 static void
 gtk_menu_realize (GtkWidget *widget)
 {
@@ -4494,9 +4507,11 @@ gtk_menu_position (GtkMenu  *menu,
       gint needed_width;
       gint needed_height;
       GtkBorder padding;
+      GtkBorder margin;
       gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
       get_menu_padding (widget, &padding);
+      get_menu_margin (widget, &margin);
 
       /* The placement of popup menus horizontally works like this (with
        * RTL in parentheses)
@@ -4537,12 +4552,12 @@ gtk_menu_position (GtkMenu  *menu,
               (!rtl && needed_width >  space_right))
             {
               /* position left */
-              x = x + padding.left - requisition.width + 1;
+              x = x - margin.left + padding.left - requisition.width + 1;
             }
           else
             {
               /* position right */
-              x = x - padding.right;
+              x = x + margin.right - padding.right;
             }
 
           /* x is clamped on-screen further down */
@@ -4588,9 +4603,9 @@ gtk_menu_position (GtkMenu  *menu,
           needed_height <= space_below)
         {
           if (needed_height <= space_below)
-            y = y - padding.top;
+            y = y + margin.top - padding.top;
           else
-            y = y + padding.bottom - requisition.height + 1;
+            y = y - margin.bottom + padding.bottom - requisition.height + 1;
 
           y = CLAMP (y, monitor.y,
                      monitor.y + monitor.height - requisition.height);